@tool
class_name CharacterData
extends Node



@export var name_str: String = "Character"
@export var max_health := DataItem.create(100, 0, Constant.MAX_FLOAT)
@export var health := DataItem.create(100, 0, 100)
@export var attack := DataItem.create(0, 0, Constant.MAX_FLOAT)
@export var defense := DataItem.create(0, 0, Constant.MAX_FLOAT)
@export var max_shield := DataItem.create(0, 0, Constant.MAX_FLOAT)
@export var shield := DataItem.create(0, 0, Constant.MAX_FLOAT)
@export var speed := DataItem.create(80, 0, Constant.MAX_SPEED)
@export var attack_speed := DataItem.create(1, 0, Constant.MAX_ATTACK_SPEED)
@export var dodge_rate := DataItem.create(0, 0, 1.0)
@export var critical_rate := DataItem.create(0, 0, 1.0)
@export var critical_degree := DataItem.create(0, 0, Constant.MAX_CRITICAL_DEGREE)

@export var fire_resistance := DataItem.create(0, 0, 1.0)
@export var ice_resistance := DataItem.create(0, 0, 1.0)
@export var thunder_resistance := DataItem.create(0, 0, 1.0)

@export var max_fire_anomaly := DataItem.create(10, 1, Constant.MAX_FLOAT)
@export var fire_anomaly := DataItem.create(0, 0, 10)

@export var max_ice_anomaly := DataItem.create(10, 1, Constant.MAX_FLOAT)
@export var ice_anomaly := DataItem.create(0, 0, 10)

@export var max_thunder_anomaly := DataItem.create(10, 1, Constant.MAX_FLOAT)
@export var thunder_anomaly := DataItem.create(0, 0, 10)

@export var weakness_list: Array[DamageInfo.DamageAttribute] = []

@export var normal_additions: Array[float]
@export var fire_additions: Array[float]
@export var ice_additions: Array[float]
@export var thunder_additions: Array[float]


func _ready() -> void:
    max_health.value_changed.connect(
        func(_ov: float, nv: float) -> void:
            health.max_value = nv
    )
    
    max_shield.value_changed.connect(
         func(_ov: float, nv: float) -> void:
            shield.max_value = nv
    )
    
    max_fire_anomaly.value_changed.connect(
        func(_ov: float, nv: float) -> void:
            fire_anomaly.max_value = nv
    )
    
    max_ice_anomaly.value_changed.connect(
        func(_ov: float, nv: float) -> void:
            ice_anomaly.max_value = nv
    )
    
    max_thunder_anomaly.value_changed.connect(
        func(_ov: float, nv: float) -> void:
            thunder_anomaly.max_value = nv
    )
    


func random_weakness_list(count: int) -> void:
    count = clampi(count, 0, DamageInfo.DamageAttribute.size() - 1)
    var attrs := DamageInfo.DamageAttribute.keys()
    attrs.pop_front()
    attrs.shuffle()
    for key: String in attrs.slice(0, count):
        weakness_list.append(DamageInfo.DamageAttribute.get(key))


# TODO 处理弱点带来的减抗效果和更容易异常的效果
func apply_weaknesses() -> void:
    pass
